package com.example.project.Service.Impl;

import com.example.project.Dao.BlogDao;
import com.example.project.Dao.CommentDao;
import com.example.project.Entity.Blog;
import com.example.project.Service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class BlogServiceImpl implements BlogService {
    @Autowired
    private BlogDao blogDao;

    @Autowired
    private CommentDao commentDao;

    @Override
    public void SaveBlog(Blog blog){
        blogDao.DeleteBlog(blog);
        blogDao.SaveBlog(blog);
    }

    @Override
    public void backBlog(int blog_id){
        commentDao.deleteCommentByBlog(blog_id);
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date = sf.format(new Date());
        blogDao.backBlog(blog_id, date);
    }

    @Override
    public void deleteBlog(int blog_id){
        Blog b = blogDao.SelectBlogById(blog_id);
        blogDao.DeleteBlog(b);
    }

    @Override
    public Blog SelectBlogById(int blog_id){
        return blogDao.SelectBlogById(blog_id);
    }

    @Override
    public void addDownLoad(int blog_id){
        blogDao.addDownLoad(blog_id);
    }

    @Override
    public void addClick(int blog_id){
        blogDao.addClick(blog_id);
    }
}
